package com.hjqjl.whdemo.feature.feature0.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.hjqjl.whdemo.BuildConfig;
import com.hjqjl.whdemo.app.SPManager;
import com.hjqjl.whdemo.base.BaseActivity;
import com.hjqjl.whdemo.databinding.ActivitySetBinding;
import com.hjqjl.whdemo.utils.NetWorkUtils;

public class SetActivity extends BaseActivity {
    public static void start(Context context) {
        Intent starter = new Intent(context, SetActivity.class);
        context.startActivity(starter);
    }

    private ActivitySetBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivitySetBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        if (SPManager.hasBlackWhite()) {
            binding.mineSwSetBlackWhite.setChecked(true);
        } else {
            binding.mineSwSetBlackWhite.setChecked(false);
        }

        binding.btnShow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean is = NetWorkUtils.hasNetwork(pActivity);
                binding.tvShow.setText("网络是否可用" + is + "--"
                        + "APP_HOST：" + BuildConfig.APP_HOST + "--"
                        + "APP_HOST_FLAG：" + BuildConfig.APP_HOST_FLAG + "--"
                        + "LOG_DEBUG" + BuildConfig.LOG_DEBUG + "--"
                        + "APP_PRODUCTID:" + BuildConfig.APP_PRODUCTID);
            }
        });

        binding.mineSwSetBlackWhite.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    SPManager.SP.put(SPManager.KEY_BLACK_WHITE, true);
                    ToastUtils.showShort("打开黑白屏");
                } else {
                    SPManager.SP.put(SPManager.KEY_BLACK_WHITE, false);
                    ToastUtils.showShort("关闭黑白屏,需重新打开Activity");
                }
            }
        });

        binding.btnCq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppUtils.relaunchApp(true);
            }
        });
    }
}